<template>
	<view class="safe-area-inset-bottom">
		<!-- 企业 联系人添加 -->
				<!-- 搜索框 -->
				<view class="swip_header">
				<view class="slot-box">
					<view style="width: 100%;">
						<uni-search-bar v-model="queryParams.params.findApi" type="text" @confirm="handleQuery" @input="handleQuery" placeholder="请输入企业名称" />
					</view>
				</view>
				</view>

			<view class="scroll_view" v-if="companyList.length !== 0">
				<view @click="selectChange(item)" v-for="(item, index) in companyList" :key="index" class="table_view">
					<view class="table_span" style="justify-content: space-between;">
						<span>{{item.companyName}}</span>
						<span style="color: #00a660;">使用</span>
						</view>
					<view class="table_span" style="font-size: 26rpx;color: #666666;">
						<span style="width: 60%;">
							<i class="iconfont grayIcon" style="margin:0 10rpx 0 0;font-size: 30rpx;"
								v-if="item.isCertify == 0">&#xe625;</i>
							<i class="iconfont greenIcon" style="margin:0 10rpx 0 0;font-size: 27rpx;"
								v-else>&#xe625;</i>
							{{item.name}}@{{item.mobile}}</span>
						<span class="over_flow">{{item.email}}</span>
					</view>
				</view>
			</view>

			<!-- 暂无数据 -->
			<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
	</view>
</template>

<script>
	import luanqingEmpty from '@/components/luanqing-empty/luanqing-empty';
	import {listCustomerCompanyStaff} from "@/api/ec/work/customer/customerCompanyStaff";
	import {getCustomerCompanyStaff} from "@/api/ec/work/customer/customerCompanyStaff";
	import {listCustomerCompanyStaffPerson} from "@/api/ec/person/customer/customerCompanyStaff";
	import {addDateRange} from "@/utils/ruoyi"
	export default {
		components: {
			luanqingEmpty
		},
		name: "selectCompanyPersonal",
		data() {
			return {
				ruleForm:[],
				dateRange:[],
				companyList: [],
				// 查询参数
				queryParams: {
				  pageNum: 1,
				  pageSize: 10,
				  tableName: undefined,
				  tableComment: undefined,
				  params: {
				    findApi: undefined
				  }
				},   
				index:0,
				companyCopy:0,   
			};
		},
		onLoad(option) {
			this.index = option.index
			this.companyCopy = option.companyCopy
			this.queryParams.customerCompanyId = option.customerCompanyId
			this.getList()
		},
		methods: {
			getList(){
				
				// 企业
				if(this.$store.getters.staffInfo.companyId !== 0 ){
				  listCustomerCompanyStaff(addDateRange(this.queryParams,this.dateRange)).then(response => {
				    this.companyList = response.rows;
				  });
				} else {
				  listCustomerCompanyStaffPerson(addDateRange(this.queryParams,this.dateRange)).then(response => {
				    this.companyList = response.rows;
				  });
				} 
			},
			/**搜索*/
			handleQuery() {
				this.getList()
			},
			/** 选择使用联系人 */
			selectChange(item) {
				getCustomerCompanyStaff(item.id).then(response => {
				  let data = response.data;
				  if(this.companyCopy){
					  let ruleForm = {sendName:data.name,id:0,sendMobile:data.mobile,sendCompany:data.companyName,senderType:0,index:this.index}
					  uni.$emit('copyCompanyStaffData',ruleForm)
				  }else{
					  let ruleForm = {signCompany:data.companyName,signerName:data.name,signerMobile:data.mobile,index:this.index}
					  uni.$emit('companyStaffData',ruleForm)
				  }
				  uni.navigateBack(1)
				})  
			},
		}
	}
</script>

<style lang="scss" scoped>
	.over_flow{
		overflow: hidden;
		white-space: normal;
		text-overflow: ellipsis;
		-webkit-line-clamp: 1; //显示行数
		// display: -webkit-box; /*作为弹性伸缩盒子模型显示*/
		-webkit-box-orient: vertical; /*伸缩盒子的排列方式：从上到下垂直*/
		width: 40%;
	}
	page {
			background: $uni-bg-color;
		}
		.scroll_view{
			position: absolute;
			top: 110rpx;
			height:80%;
			width: 100%;
			overflow-y: scroll;
		}
	
	.table_view {
		border-bottom: 1rpx solid #ebeef5;
		padding: 15rpx 20rpx 15rpx 0;
		margin: 0 20rpx;
	}

	.table_span {
		margin-top: 15rpx;
		display: flex;
		align-items: center;
		color: #000;
	}

</style>
